﻿Imports System.Data.SqlClient

Public Class clsE_Porcentajes
    Private mintIdPorcentajes As Integer
    Private mdblServicios As Double
    Private mdblPuntualidad As Double
    Private mdblPresentacion As Double
    Private mdblRendimiento As Double
    Private mdblVentas As Double
    Private mdblBloqueos As Double
    Private mdblTotal As Double
    Public Property IdPorcentajes() As Integer
        Get
            Return mintIdPorcentajes
        End Get
        Set(ByVal value As Integer)
            mintIdPorcentajes = value
        End Set
    End Property
    Public Property Servicios() As Double
        Get
            Return mdblServicios
        End Get
        Set(ByVal value As Double)
            mdblServicios = value

        End Set
    End Property
    Public Property Puntualidad() As Double
        Get
            Return mdblPuntualidad
        End Get
        Set(ByVal value As Double)
            mdblPuntualidad = value

        End Set
    End Property
    Public Property Presentacion() As Double
        Get
            Return mdblPresentacion
        End Get
        Set(ByVal value As Double)
            mdblPresentacion = value

        End Set
    End Property
    Public Property Rendimiento() As Double
        Get
            Return mdblRendimiento
        End Get
        Set(ByVal value As Double)
            mdblRendimiento = value

        End Set
    End Property
    Public Property Ventas() As Double
        Get
            Return mdblVentas
        End Get
        Set(ByVal value As Double)
            mdblVentas = value

        End Set
    End Property
    Public Property Bloqueos() As Double
        Get
            Return mdblBloqueos
        End Get
        Set(ByVal value As Double)
            mdblBloqueos = value

        End Set
    End Property

    Public Property Total() As Double
        Get
            Return mdblTotal
        End Get
        Set(ByVal value As Double)
            mdblTotal = value
        End Set
    End Property
    Public Sub New()
        mintIdPorcentajes = 0
        mdblServicios = 0
        mdblPuntualidad = 0
        mdblPresentacion = 0
        mdblRendimiento = 0
        mdblVentas = 0
        mdblBloqueos = 0
        mdblTotal = 0
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into E_Porcentajes (" & _
                            "IdPorcentaje," & _
                            "Servicios," & _
                            "Puntualidad," & _
                            "Presentacion," & _
                            "Rendimiento," & _
                            "Ventas," & _
                            "Bloqueos," & _
                            "Total) " & _
                            "VALUES (" & _
                            "@IdPorcentaje," & _
                            "@Servicios," & _
                            "@Puntualidad," & _
                            "@Presentacion," & _
                            "@Rendimiento," & _
                            "@Ventas," & _
                            "@Bloqueos," & _
                            "@Total) "

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdPorcentaje", mintIdPorcentajes)
        Command.Parameters.AddWithValue("Servicios", mdblServicios)
        Command.Parameters.AddWithValue("Puntualidad", mdblPuntualidad)
        Command.Parameters.AddWithValue("Presentacion", mdblPresentacion)
        Command.Parameters.AddWithValue("Rendimiento", mdblRendimiento)
        Command.Parameters.AddWithValue("Ventas", mdblVentas)
        Command.Parameters.AddWithValue("Bloqueos", mdblBloqueos)
        Command.Parameters.AddWithValue("Total", mdblTotal)

        cnConn.Open()
        Dim RowsAffected As Integer
        Try
            RowsAffected = Command.ExecuteNonQuery
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Aviso")
        End Try

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el registro de porcentajes", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
    Sub Actualizar()
        Dim strSqlQry As String
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        strSqlQry = "Update E_Porcentajes Set " & _
                            "Servicios=@Servicios," & _
                            "Puntualidad=@Puntualidad," & _
                            "Presentacion=@Presentacion," & _
                            "Rendimiento=@Rendimiento," & _
                            "Ventas=@Ventas," & _
                            "Bloqueos=@Bloqueos," & _
                            "Total=@Total " & _
                            " Where IdPorcentaje=@IdPorcentaje"


        Dim Command As New SqlCommand(strSqlQry, cnConn)
        Command.Parameters.AddWithValue("IdPorcentaje", mintIdPorcentajes)
        Command.Parameters.AddWithValue("Servicios", mdblServicios)
        Command.Parameters.AddWithValue("Puntualidad", mdblPuntualidad)
        Command.Parameters.AddWithValue("Presentacion", mdblPresentacion)
        Command.Parameters.AddWithValue("Rendimiento", mdblRendimiento)
        Command.Parameters.AddWithValue("Ventas", mdblVentas)
        Command.Parameters.AddWithValue("Bloqueos", mdblBloqueos)
        Command.Parameters.AddWithValue("Total", mdblTotal)

        cnConn.Open()

        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible actualizar el registro de porcentajes", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If



    End Sub
End Class
